home *** CD-ROM | disk | FTP | other *** search
- Path: nntp-hub.barrnet.net!biosys!apldbio.com
- From: nasser@apldbio.com (Nasser Abbasi)
- Newsgroups: comp.lang.c++
- Subject: exit() and flushing data to ofstream files?
- Message-ID: <31584F18.29B2@apldbio.com>
- Date: 26 Mar 96 20:10:00 GMT
- Sender: news@biosys.apldbio.COM
- Organization: Applied BioSystems
- X-Mailer: Mozilla 2.01 (X11; I; SunOS 5.5 sun4m)
- MIME-Version: 1.0
- CC: nasser@apldbio.com
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
-
- hi,
-
- I am confused about something.
-
- according to "the C++ programming language", Bjarne Stroustrup
- page 85 it says:
- "..This can be done by calling exit(), which first clean things
- like output streams."
-
- I take this as meaning that calling exit() from your C++
- program will cause buffers to be flushed out to ofstream
- files . well, this does no seem to be the case, this little
- program shows that exit() do not flush data to file.
-
- #include <fstream.h>
- #include <stdlib.h>
-
- main()
- {
- ofstream f;
-
- f.open("tmp1");
- f.put('X');
- //f.flush();
- exit(1); // this does not flush data to file
- return 1;
-
- }
-
- Now looking at tmp I see no data in it.
-
- This is on Sun Solaris 2.5, using CC compiler.
-
- What is the recommended way to terminate the program
- and have all buffers flushed automatically without having
- to explicity call flush() on each open stream file ?
- Is this a bug or a feature of exit() ?
-
- thanks,
- Nasser
- Applied BioSystems
-